package ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("图书借阅");
        System.out.println("请输入你要借的图书的名字");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int currentSize= bookList.getUsedSize();
        int i=0;
        for(;i<currentSize;i++){
            //创建一个Book类对象记录查询到的图书
            Book book=bookList.getBook(i);
           if(book.getName().equals(name)){
               if(book.isBorrowed()){
                   System.out.println("该数已经借出");
                   return;
               }
               //将isBorrowed的值设为true，则表示借书成功
               book.setBorrowed(true);
               System.out.println("借书成功");
               return;
           }
        }
        System.out.println("没有你想借的书");
    }
}
